package snail19.baseServer.baseServerImpl;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;

import snail19.baseDao.BaseDao;
import snail19.baseServer.BaseServer;

@SuppressWarnings("unchecked")
public abstract class BaseServerImpl<T> implements BaseServer<T> {
	private Class<T> clazz;
	protected BaseServerImpl (){
		ParameterizedType type = (ParameterizedType) this.getClass().getGenericSuperclass();
		this.clazz=(Class<T>) type.getActualTypeArguments()[0];
	}
	
	
	
	private BaseDao<T> basedao;
	//注入具体的dao的实现
	 public void setBasedao(BaseDao<T> basedao) {
		this.basedao = basedao;
	}
	
	@Override
	public void saveEntity(T t) {
        this.basedao.saveEntity(t);
	}

	@Override
	public void deleteEntity(T t) {
		this.basedao.deleteEntity(t);
	}

	@Override
	public void updateEntity(T t) {
		this.basedao.updateEntity(t);
	}

	@Override
	public void bachEntity(String hql, Object... objects) {
		this.basedao.bachEntity(hql, objects);
	}

	@Override
	public T getEntity(Serializable id) {

		return this.basedao.getEntity(id);
	}

	@Override
	public T loadEntity(Serializable id) {
		return this.basedao.loadEntity(id);
	}

	@Override
	public List<T> findEntityByHQL(String hql, Object... objects) {
		return this.basedao.findEntityByHQL(hql, objects);
	}

	@Override
	public List<T> findall() {
		String hql="from"+this.clazz.getSimpleName();
		return this.findEntityByHQL(hql);
	}

}
